package com.ruoyi.tt.controller;

import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.constant.Constants;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.tt.domain.TtUser;
import com.ruoyi.tt.service.LoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * @author
 * @date 2022/10/16 9:15
 **/
@RestController
@RequestMapping("/api/v1")
public class LoginController {

    @Autowired
    private LoginService loginService;

    @Anonymous // 不需要权限就可以访问
    @PostMapping("/login")
    public AjaxResult login(HttpServletRequest request, @RequestBody TtUser user) {
        AjaxResult ajax = AjaxResult.success();
        // 生成令牌
        String token = loginService.login(user);
        ajax.put(Constants.TOKEN, token);
        System.out.println("user = " + user);
        return AjaxResult.success(token);
    }


}
